import { createStore } from 'vuex'
import createPersistedState from "vuex-persistedstate" //vuex数据持久化
export default createStore({
  // 设置属性
  plugins: [createPersistedState({
    storage:window.localStorage,
  })],
  state: {
    isLogin:{
      state:false,
      rank:-1,
      tokenID: "",//令牌id
      token:"",
      userID: "",//用户id
      userName: ""
    }, 
    rankOption:[
    ]  
  },
  getters: {
    //获取登录token
    isLoginToke: state => { return state.isLogin.token}, 
   },
   // 设置属性状态
  mutations: {  
    setIsLogin(STATE,{state,token,rank,userName,userID,tokenID} ) {
      STATE.isLogin = {state,token,rank,userName,userID,tokenID}
     }, 
     setToken(STATE, commitData){
      STATE.isLogin.token = commitData 
     },
     outLogin(STATE){
        STATE.isLogin={} 
     }
  }, 
  //异步获取状态
  actions: { 
    // setUser(commit, flag) {
    //   commit("userStatus", flag)
    //  }, 
  }
})





 